package com.jerry.study;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by chedejun on 2017/1/10.
 */
@Slf4j
@Service
public class RedisService {
    @Autowired
    RedisTemplate<String, String> redisTemplate;

    public void insert() {
        redisTemplate.opsForValue().set("123", "qweq");
    }

    @Cacheable(cacheNames = "users", key = "#userBo.userId")
    public void insert(final UserBo userBo) {
        log.info("====" + userBo.toString());
    }

    @Cacheable(cacheNames = "users", key = "#userId")
    public UserBo get(final String userId) {
        return new UserBo();
    }

    @Cacheable(cacheNames = "users", key = "#userBo")
    public UserBo insert1(final String userBo) {
        log.info("====" + userBo);
        final UserBo userBo1 = new UserBo();
        userBo1.setAge(13);
        return userBo1;
    }

    @Cacheable(cacheNames = "users", key = "#userId.toString()")
    public UserBo get1(final String userId) {
        return new UserBo();
    }
}
